from django.db import models

from user.models import UserModel


# Create your models here.
#图书分类
class TypeModel(models.Model):
    typename=models.CharField(max_length=50)
    class Meta:
        db_table='type'

#作者表
class WriterModel(models.Model):
    writername=models.CharField(max_length=50)
    class Meta:
        db_table='writer'

#出版社
class CreateAddressModel(models.Model):
    crestename=models.CharField(max_length=50)
    class Meta:
        db_table='create_address'

#图书表
class BooksModel(models.Model):
    img=models.CharField(max_length=100)
    bookname=models.CharField(max_length=100,verbose_name='图书名称')
    typename=models.ForeignKey(TypeModel,on_delete=models.CASCADE,verbose_name='图书分类')
    writername=models.ForeignKey(WriterModel,on_delete=models.CASCADE,verbose_name='作者')
    yiname=models.CharField(max_length=20,verbose_name='译者',null=True,blank=True)
    createname=models.ForeignKey(CreateAddressModel,on_delete=models.CASCADE,verbose_name='出版社')
    createtime=models.DateField(verbose_name='出版时间')
    price=models.DecimalField(max_digits=10,decimal_places=2,verbose_name='单价')
    shujianame=models.CharField(max_length=100,verbose_name='书架名称')
    count=models.IntegerField(default=1,verbose_name='库存数量')
    isdianzi=models.IntegerField(choices=((0,'否'),(1,'是')),default=0,verbose_name="是否电子资料")
    bookslevel=models.IntegerField(choices=((0,'无'),(1,'初级'),(2,'中级'),(3,'高级')),default=0,verbose_name="图书密级")
    isbuy=models.IntegerField(choices=((0,'否'),(1,'是')),default=0,verbose_name='是否购买过')
    content=models.TextField(verbose_name='图书内容',default=0)
    class Meta:
        db_table='books'

#评价
class CommitModel(models.Model):
    userid=models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name='用户id')
    bookid=models.ForeignKey(BooksModel,on_delete=models.CASCADE,verbose_name='图书id')
    commitname=models.CharField(max_length=50,verbose_name='评价人')
    commitcontent=models.TextField(verbose_name='评价内容')
    committime=models.DateField(verbose_name='评价时间')
    class Meta:
        db_table='committable'

